Skip to content

Add configurable per-profile context window setting#9352

Open
coolcom200 wants to merge 1 commit intomasterfrom
leon/configurable-context-window
Open

Add configurable per-profile context window setting#9352
coolcom200 wants to merge 1 commit intomasterfrom
leon/configurable-context-window

Conversation

@coolcom200
Copy link
Copy Markdown

Description

Adds a per-profile context window control for the agent's base model, gated behind the new configurable_context_window feature flag. Users can override the model's default context window from both the AI settings page and the profile editor.

  • New Context window row beneath the base model dropdown: [min — slider — max] [numeric input]. The control hides if the active base model isn't configurable, if global AI is disabled, or if the feature flag is off.
  • Slider and input clamp to the model's advertised [min, max] range, snap to nicely-rounded values, and stay in sync with each other on drag, commit, profile refresh, model change, and AISettings updates.
  • Picking a new base model resets any persisted context window override; if the resulting model isn't configurable or is missing, the stale override is cleared.
  • Persistence is via AIExecutionProfilesModel::set_context_window_limit, plumbed through RequestParams.context_window_limit so the agent request reflects the user's choice.
  • GraphQL plumbing: introduces a local Uint32 newtype mapped to schema's Uint scalar (orphan-rule workaround for cynic), and wires LlmContextWindow { is_configurable, min, max, default } through LlmInfo for both get_feature_model_choices and workspace queries.
  • warpui_core slider gains snap-value support, used to render reasonable tick stops across very wide ranges.

Testing

  • New unit tests in app/src/ai/execution_profiles/editor/mod_test.rs covering snap-value generation across small, large, offset, equal-min/max, and min>max ranges.
  • cargo nextest run -p warp --features configurable_context_window snap_values context_window passes locally.
  • cargo check -p warp --features configurable_context_window passes with no warnings.
  • Manual UI checks: changing base model resets the override; toggling global AI hides the row and no-ops drag/commit/blur; values persist across profile reopen; settings page and profile editor stay in sync after async refreshes.

Server API dependencies

  • Is this change necessary to make the client compatible with a desired server API breaking change?
  • Does this change rely on a new server API?
    • If so, is the use of this API restricted to client channels that rely on the staging server (e.g. WarpDev)? Gated behind FeatureFlag::ConfigurableContextWindow.
  • Is this change enabling the use of a server API on client channels that rely on the production server (e.g. WarpStable)?

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

Changelog Entries for Stable

CHANGELOG-OZ: Configurable max context window per profile.

Conversation link

Co-Authored-By: Oz oz-agent@warp.dev

Lets users override the agent base model's context window from
settings and from the profile editor. The slider/input
clamp to the model's advertised range, persist via
AIExecutionProfilesModel, reset when the base model changes, and
hide when global AI is disabled or the model isn't configurable.
@cla-bot cla-bot Bot added the cla-signed label Apr 29, 2026
@oz-for-oss
Copy link
Copy Markdown

oz-for-oss Bot commented Apr 29, 2026

@coolcom200

I'm starting a first review of this pull request.

You can follow along in the session on Warp.

I completed the review and posted feedback on this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

I completed the review and posted feedback on this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Copy link
Copy Markdown

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds a feature-flagged per-profile context-window override, including UI controls in AI settings and the profile editor, GraphQL model metadata plumbing, request propagation, telemetry, and slider snapping support.

Concerns

  • The new contextWindow GraphQL field is selected unconditionally, so clients can fail against servers that have not deployed the new API even when the client feature flag is disabled.
  • Invalid model metadata with min > max can still reach UI/action paths that call u32::clamp, which panics on inverted bounds.
  • The outbound request copies the raw persisted context-window override without revalidating it against current model metadata, allowing stale out-of-range or non-configurable limits to be sent.
  • The AI settings slider does not use the snap-value path added for the profile editor, so the two entry points behave inconsistently.

Verdict

Found: 0 critical, 3 important, 1 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread crates/graphql/src/api/queries/get_feature_model_choices.rs
Comment thread app/src/ai/execution_profiles/mod.rs
Comment thread app/src/ai/agent/api.rs
.ui_builder()
.slider(view.context_window_slider_state.clone())
.with_range(min as f32..max as f32)
.with_default_value(current_value as f32)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 [SUGGESTION] The settings-page slider never installs the snap values, so drag/click here emits arbitrary token counts while the profile editor snaps to rounded stops; wire the same context_window_snap_values(min, max) path into this slider for consistent behavior.

Copy link
Copy Markdown

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds a feature-flagged per-profile context window limit, including GraphQL model metadata plumbing, profile persistence, request serialization, and slider/input UI in both AI settings and the profile editor.

Concerns

  • The new GraphQL contextWindow field is requested unconditionally, so the feature flag does not protect production/stable clients from servers that have not deployed the schema yet.
  • Server-provided context-window bounds are not fully validated before UI code reaches u32::clamp, which can panic on invalid min > max data.
  • Persisted context-window overrides are read straight into request params without revalidating against the current model range/configurability.
  • The AI settings slider omits the snap values used by the profile editor, so the two entry points can persist different classes of values.

Verdict

Found: 0 critical, 4 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

pub provider: LlmProvider,
pub host_configs: Vec<RoutingHostConfig>,
pub pricing: LlmPricing,
pub context_window: LlmContextWindow,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [IMPORTANT] This field is added to the workspace fragment unconditionally. Feature-flagging the UI/request path does not stop stable clients from sending this query, so clients pointed at a server without LlmInfo.contextWindow will fail before the flag can help. Make the server field available on all target servers first, or avoid adding it to production-bound queries until it is safe.

.and_then(|id| prefs.get_llm_info(id))
.map(|info| info.context_window.clone())
.unwrap_or_else(|| prefs.get_default_base_model().context_window.clone());
if cw.is_configurable && cw.max > 0 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [IMPORTANT] context_window is server-provided; if min > max, this still returns Some and the UI/action paths later call u32::clamp(min, max), which panics. Treat invalid ranges as non-configurable here.

Suggested change
if cw.is_configurable && cw.max > 0 {
if cw.is_configurable && cw.max > 0 && cw.min <= cw.max {

Comment thread app/src/ai/agent/api.rs
.as_ref()
.is_none_or(|t| matches!(t, crate::terminal::model::session::SessionType::Local));

let context_window_limit = AIExecutionProfilesModel::as_ref(app)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [IMPORTANT] This pulls the persisted limit directly into RequestParams without validating it against the active base model's advertised range/configurability. A stale or corrupted cloud profile can still send an out-of-range limit even though the UI clamps user input; derive this through the context-window helper and clamp or clear before sending.

.ui_builder()
.slider(view.context_window_slider_state.clone())
.with_range(min as f32..max as f32)
.with_default_value(current_value as f32)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [IMPORTANT] The AI settings slider never calls with_snap_values, unlike the profile editor, so dragging or clicking here persists arbitrary token counts instead of the nicely-rounded values generated and tested by context_window_snap_values. Share that helper and apply the same snap list here.

@coolcom200 coolcom200 requested a review from szgupta April 29, 2026 01:49
Copy link
Copy Markdown
Member

@szgupta szgupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already reviewed these changes in a separate PR

Comment thread app/src/ai/agent/api.rs
pub computer_use_model: LLMId,
pub is_memory_enabled: bool,
pub warp_drive_context_enabled: bool,
pub context_window_limit: Option<u32>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u32 makes sense. this is coming from the server so we need it to explicitly be 32-bit rather than machine-dependent (usize).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants